/*
 * @Author: 黑白灰01 3193273703@qq.com
 * @Date: 2025-08-29 17:46:50
 * @LastEditors: 黑白灰01 3193273703@qq.com
 * @LastEditTime: 2025-09-01 14:12:02
 * @FilePath: /hei-oa/src/app.module.ts
 * @Description: app模块
 */
import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';
import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './user/entities/user.entity';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { UtilsModule } from './utils/utils.module';

@Module({
  imports: [
    // 配置环境变量模块
    ConfigModule.forRoot({
      isGlobal: true, // 全局可用
      envFilePath: '.env', // 指定.env文件路径
    }),
    UserModule,
    // 使用环境变量配置数据库
    TypeOrmModule.forRootAsync({
      useFactory: (configService: ConfigService) => ({
        type: configService.get<'mysql'>('DB_TYPE'),
        host: configService.get<string>('DB_HOST'),
        port: configService.get<number>('DB_PORT'),
        username: configService.get<string>('DB_USERNAME'),
        password: configService.get<string>('DB_PASSWORD'),
        database: configService.get<string>('DB_DATABASE'),
        entities: [User],
        synchronize: true, // 生产环境建议设为false
        logging: true, // 开发环境可开启日志
      }),
      inject: [ConfigService],
    }),
    UtilsModule,
  ],
  controllers: [],
  providers: [
    AppService
  ],
})
export class AppModule { }